using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFGameFramework;
public class Hight : View

{
    #region 字段
    private Transform targetPos; // 背景上的Pos节点

    private Transform CreatePos;
    private float moveSpeed = 4f; // 背景移动速度

    public float leftBoundX = -20.0f;  
    #endregion

    #region 生命周期
    // private void Update()
    // {
    //     if (targetPos != null)
    //     {
    //         // 方法1：朝着Pos位置移动
    //         Vector3 direction = (targetPos.position - transform.position).normalized;
    //         transform.position += direction * moveSpeed * Time.deltaTime;
    //     }
    //     else 
    //     {
    //         Debug.LogError("Bottom.targetPos is null");
    //     }
    // }

    void Update()
    {
        // 向左移动
        transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);

        // 如果移出屏幕左侧，就把它移到最右边继续循环
        if (transform.position.x < leftBoundX)
        {
            Close();
        } 
    }
    #endregion
    #region 重写方法
    public override void OnLoaded(params object[] param)
    {
        base.OnLoaded(param);

        // 找到Pos节点
        // targetPos = param[0] as Transform;
        moveSpeed =  4f;
        CreatePos = GameObject.Find("CreatePos").GetComponent<Transform>();
        Debug.Log("CreatePos.position = " + CreatePos.position);
        this.transform.position = CreatePos.position;
        
    }
    #endregion
}
